<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon" ></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">  {{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                     {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                                <i :class="subItem.icon" ></i> {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
        <el-card class="update" v-show="!collapse">
            <div slot="header" class="clearfix">
                <span>数据更新时间</span>
                <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
            </div>
            <div class="text item">
               打卡 {{ updatedata.ctime | timeformat() }}
            </div>
            <div class="text item">
              忘打卡 {{updatedata.ftime | timeformat() }}
            </div>
             <div class="text item">
               加班 {{ updatedata.otime | timeformat() }}
            </div>
            <div class="text item">
              请假 {{updatedata.ltime | timeformat() }}
            </div>
             
        </el-card>
       
    </div>
</template>

<script>
    import bus from '../common/bus';
    import moment from 'moment';
    export default {
        data() {
            return {
                updatedata:{},
                collapse: false,
                items: [
                    {
                        icon: 'icon-home evrg-icon',
                        index: 'homepage',
                        title: '系统首页'
                    },
                    {
                        icon: 'icon-table evrg-icon',
                        index: 'table',
                        title: '导出报表'
                    },
                    {
                        icon: 'icon-advice evrg-icon',
                        index: 'advice',
                        title: '意见反馈'
                    },
                    {
                        icon: 'icon-user-manager evrg-icon',
                        index: '3',
                        title: '用户管理',
                        subs: [
                            {
                                index: 'editpassword',
                                icon: 'icon-user-edit-password evrg-icon',
                                title: '修改密码'
                            },
                            {
                                index: 'userlist',
                                icon: 'icon-user-group evrg-icon',
                                title: '人员列表'
                            },
                            {
                                index: 'upload',
                                icon: 'icon-upload evrg-icon',
                                title: '文件上传'
                            }
                        ]
                    }
                  
                ]
            }
        },
        filters: {
            timeformat:function(input){
                return moment(input).format('YYYY-MM-DD HH:mm')
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
            this.$axios.post('/user/getlast')
                .then(data=>{
                    if(data.code==200){
                        this.updatedata=data.time;
                    }
                  })
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 250px;
    }
    .sidebar > ul {
        height:100%;
    }
    .update{
        position: absolute;
        bottom: 30px;
        left: 10px;
        background-color:transparent;
        color: #ffffff;
    }
    .text {
        font-size: 14px;
    }
    .item {
        margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }
    
</style>
